package com.practise.servercustome.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class CustomeControl {
    public static final String url = "http://serviceProvide";

    @Autowired
    private DiscoveryClient discoveryClient;

    @Resource
    RestTemplate restTemplate;

    @RequestMapping("/helloresponse")
    public String helloResp(){
        log.info("DiscoveryClient: {}", discoveryClient.getClass().getName());
        discoveryClient.getInstances("server_produce_zook").forEach(s -> {
            log.info("Host: {}, Port: {}", s.getHost(), s.getPort());
        });
        String helloResponse =  restTemplate.getForObject(url+"/hellorequest",String.class);
        return helloResponse;
    }
}
